package com.wyw.leetcode.learning.simple;

import com.wyw.leetcode.simple.parent.VersionControlTopic278;

/**
 * leetcode topic 278
 * 第一个错误的版本
 *
 * @Author Mr Wu （yewen.wu.china@gmail.com）
 * @Date 2021/11/4 10:28
 */
public class Topic278 extends VersionControlTopic278 {
    public static void main(String[] args) {
        System.out.println(firstBadVersion(5));
    }

    public static int firstBadVersion(int n) {
        int left = 1;
        int right = n;
        while ( left < right ) {
            int mid = left + (right - left) / 2;
            if(VersionControlTopic278.isBadVersion(mid))  {
                right = mid;
            } else {
                left = mid +1;
            }
        }
        return right;
    }
}
